#include<iostream>
#include"SingleLinkedList.h"
using namespace std;







// 主函数，测试链表反转
int main() {
    // 创建链表：1 -> 2 -> 3 -> 4 -> 5
    ListNode* head = new ListNode(1);
    head->next = new ListNode(2);
    head->next->next = new ListNode(3);
    head->next->next->next = new ListNode(4);
    head->next->next->next->next = new ListNode(5);

    // cout << "原链表: ";
    // printList(head);

    // // 反转链表
    // //head = reverseList(head);
    // int n  = 2;
    // head = removeNthFromEnd(head,n);

    // cout << "反转后: ";
    // printList(head);


    //环形链表
    if(hasCycle(head))
    {
        cout<<"链表中存在环!"<<endl;
    }
    else
    {
        cout<<"链表中不存在环"<<endl;
    }

    //return 0;



    //160相交链表的测试
       // 创建两个相交链表
       ListNode* common = new ListNode(8);
       common->next = new ListNode(4);
       common->next->next = new ListNode(5);
   
       ListNode* headA = new ListNode(4);
       headA->next = new ListNode(1);
       headA->next->next = common; // A: 4 -> 1 -> 8 -> 4 -> 5
   
       ListNode* headB = new ListNode(5);
       headB->next = new ListNode(6);
       headB->next->next = new ListNode(1);
       headB->next->next->next = common; // B: 5 -> 6 -> 1 -> 8 -> 4 -> 5
   
       ListNode* intersection = getIntersectionNode(headA, headB);
    //    if (intersection) {
    //        cout << "相交于节点: " << intersection->val << endl;
    //    } else {
    //        cout << "不相交" << endl;
    //    }

   
       return 0;
}


